const Rx = require('../../../library/reactivex/rx.js')
var app =getApp();
const userInfo = {

  // getUserInfo: (options = {}) => {
  //   return new Promise((resolve, reject) => {
  //     checkUserInfo().then((res) => {
  //       options.success = resolve;
  //       options.fail = reject;
  //       wx.getUserInfo(options);
  //     },(er)=>{})
  //   })
  // },

  getUserInfo: (options = {}) => {
    return new Promise((resolve, reject) => {
      // app.userInfoObser ='userInfoObser'
      // Rx.observable(app.userInfoObser)
      //   .then(userInfo=>{
      //     resolve(userInfo);
      //   })
      checkUserInfo().then((res) => {

      }, (err) => { 
        app.userInfoObser = 'UserInfoObser'
        Rx.observable(app.userInfoObser)
          .then(userInfo => {
            resolve(app.getUserInfo);
          })
        wx.navigateTo({
          url: `../getUserInfo/getUserInfo`,
        })
      })
    })
  }
};


/***
* @desc 检查是否拒绝授权
* 
*/
function checkUserInfo() {
  return new Promise((resolve, reject) => {
    app.getUserInfo.userInfo?resolve():reject();
  })
}
/***
* @desc 检查是否拒绝授权
* 
*/
function checkAuth() {
  return new Promise((resolve, reject) => {
    wx.authorize({
      scope: 'scope.userInfo',
      success: function (res) {
        resolve();
      },
      fail: function (res) {
        //如果拒绝过授权
        wx.showModal({
          title: '提示',
          content: '为了更好的使用PoorSir请允许她获取您的用户信息',
          success: function (res) {
            if (res.confirm) {
              wx.openSetting({
                success: (res) => {
                  res.authSetting = {
                    "scope.userInfo": true
                  }
                },
                fail: function (err) {
                }
              })
            }
          }
        })
        reject();
      }
    })
  })
}




module.exports = userInfo;